package com.syn.synold4s.repository;

import android.text.TextUtils;

import com.gaoyi.basemodule.baseCallback.Callback;
import com.gaoyi.basemodule.baseCallback.OnResultListener;
import com.gaoyi.basemodule.baseUtil.OKHttpUtil;
import com.syn.synold4s.bean.dto.AlertNotifyDto;
import com.syn.synold4s.bean.dto.GoogleMapBean;

import java.lang.reflect.Type;
import java.util.List;

public class MqttRepository {
    public void getAddress(AlertNotifyDto bean, String language, OnResultListener onResultListener, Type typeofT) {
        OKHttpUtil.getInstance().getAsync("https://maps.googleapis.com/maps/api/geocode/json?latlng=" + bean.getLat() + "," + bean.getLng() + "&language=" + language + "&key=AIzaSyAf_LvhnV6TDlfvp-iddWSFFsJb3RHGmyw", new Callback() {
            @Override
            public void onSuccess(Object obj) {
                GoogleMapBean googleMapBean = (GoogleMapBean) obj;
                if (googleMapBean != null && googleMapBean.getResults() != null && !googleMapBean.getResults().isEmpty()) {
                    List<GoogleMapBean.ResultsBean> results = googleMapBean.getResults();
                    String compoundCode = "";
                    if (!results.isEmpty()) {
                        compoundCode = googleMapBean.getResults().get(0).getFormatted_address();
                    }
                    if (!TextUtils.isEmpty(compoundCode)) {
                        bean.setAddress(compoundCode);
                        onResultListener.onSuccess(bean);
                    }
                }
            }

            @Override
            public void onFailed(Exception e) {
            }
        }, typeofT);
    }
}
